/**
 * 
 */
package neptune.manager.validator.core;

import neptune.manager.builder.IPAddressRange;
import neptune.manager.model.topology.IPAddress;
import neptune.manager.model.topology.NetworkInterface;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.IpAddressValidator;
import neptune.manager.validator.Validator;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.rules.netif.ControlAddressNumberRule;
import neptune.manager.validator.rules.netif.ControlInterfaceNameRule;
import neptune.manager.validator.rules.netif.IPAddressNumberRule;
import neptune.manager.validator.rules.netif.NetInterfaceNameDefinitionRule;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class CoreNetInterfaceValidator extends Validator<NetworkInterface> {

	protected Validator<IPAddress> validator;

	public CoreNetInterfaceValidator(IPAddressRange controlIpRange) {
		addRule(new NetInterfaceNameDefinitionRule());
		addRule(new ControlInterfaceNameRule());
		addRule(new ControlAddressNumberRule());
		addRule(new IPAddressNumberRule());
		validator = new IpAddressValidator(controlIpRange);
	}

	@Override
	public String getName() {
		return "CoreNetInterfaceValidator";
	}

	@Override
	protected ValidatorResult validationAlgorithm(NetworkInterface toValidate,
			ValidatorResult result) {

		result.getLog().addMessage(
				"Validating network interface '"
						+ toValidate.getInterfaceName() + "'",
				MessageType.NORMAL);

		for (IPAddress ipAddr : toValidate.getIpAddresses()) {
			validator.validate(ipAddr, result);
		}

		return result;
	}

}
